/*
 * SparseArrayCase.cpp
 *
 *  Created on: 2012-10-30
 *      Author: yangentao@gmail.com
 */

#include "test.h"
#include "../src/yet/SparseArray.h"
using namespace  yet;

TEST(Sparse, construct1) {
	SparseArray<int> arr;
	EXPECT_EQ(0, arr.length());
	int n = -1;

	arr.put(1, 100);
	EXPECT_EQ(1, arr.length());
	n = arr.get(1);
	EXPECT_EQ(n, 100);
	n = arr.valueAt(0);
	EXPECT_EQ(n, 100);

	arr.put(5, 500);
	EXPECT_EQ(2, arr.length());
	n = arr.get(5);
	EXPECT_EQ(n, 500);
	n = arr.valueAt(1);
	EXPECT_EQ(n, 500);

	arr.remove(5);

	EXPECT_EQ(1, arr.length());
	n = arr.get(1);
	EXPECT_EQ(n, 100);
	n = arr.valueAt(0);
	EXPECT_EQ(n, 100);

	arr.append(5, 500);

	EXPECT_EQ(2, arr.length());
	n = arr.get(5);
	EXPECT_EQ(n, 500);
	n = arr.valueAt(1);
	EXPECT_EQ(n, 500);
}

